<include file="public/header"/>
<body style="background:#fff">
<header>
<div class="tab_nav">
   <div class="header">
     <div class="h-left"><a class="sb-back" href="javascript:history.back(-1)" title="返回"></a></div>
     <div class="h-mid">店面销售报表</div>
     <div class="h-right">
       <aside class="top_bar">
         <div onClick="show_menu();$('#close_btn').addClass('hid');" id="show_more"><a href="javascript:;"></a> </div>
       </aside>
     </div>
   </div>
 </div>
</header>
<link rel="stylesheet" href="__STATIC__/css/weui.css">
<link rel="stylesheet" href="__STATIC__/css/weui2.css">
<style>
.shopactive{padding:0;}
.tab_hd{border-bottom: 1px solid #ccc;}
.tab_hd ul{display: flex;}
.tab_hd ul li{flex:1;text-align: center;}
.tab_hd ul li a{margin:0 auto;display: inline-block;height: 40px;font-size:14px;}
.tab_hd ul li a.on{border-bottom:2px solid #ec3913;color:#ec3913;}
.action table {margin-top:8px;color:#666;}
.action table tr{border-bottom: 1px solid #eee}
.action table tr td{text-align: center;border-left: 1px solid #ccc;padding:2px 4px;}
.action table tr th{background: #eee;}
.select-bar input{border:1px solid #ccc;height: 20px;width:40%;font-size:13px;background: #fff}
.select-bar button{ width:90%;height:30px;color:#333;border:1px solid #ccc;}
.select-bar{display: flex;align-items: center;}
.select-bar .content{width: 85%}
.select-bar .search_btn{width: 15%;text-align: center;}
</style>
<div id="shopactive">
<!--  <div class="tab_hd">
      <ul>
        <li><a href="javascript:void(0)" onclick="tabindex(1)" class="tab_head1 on">会员政策</a></li>
        <li><a href="javascript:void(0)" onclick="tabindex(2)" class="tab_head2">分销政策</a></li>
        <li><a href="javascript:void(0)" onclick="tabindex(3)" class="tab_head3">优惠促销</a></li>
        <li><a href="javascript:void(0)" onclick="tabindex(4)" class="tab_head4">订单促销</a></li>
      </ul>
  </div> -->
  

  <div class="select-bar">
        <div class="content">
        <label for="time">
          <input name="start_time" id="start_time" placeholder="*开始日期" type="text"/>~<input name="end_time" id="end_time" placeholder="*结束日期" type="text"/>
        </label>
       
    
          <div class="weui_cell_bd weui_cell_primary">
              <input class="weui_input" type="text" value="" id='shop_list' placeholder="选择店面" style="width:83%"/>
          </div>
    
        
        </div>
        <div class="search_btn">
          <button type="button" id="search" class="sub_btn" data="search">查询</button>
          <if condition="$is_mobile eq 0">
          <form method="post" action="{:U('User/parse2excel')}" id="export">
              <button type="button" id="putout" onclick="TableToJson('shoptable')">导出</button>
              <input type="hidden" value="" id="jsondata" name="txt"/>
              <input type="hidden" value="" id="title" name="title"/>
          </form>
          </if>
        </div>
  </div>

  <div class="action ajax_return" style="width:100%;overflow-x:scroll" id="wrapper">
    

  </div>
</div> 

</body>
 <script src="__PUBLIC__/js/mobiscroll.core-2.5.2.js" type="text/javascript"></script>
 
 <script src="__PUBLIC__/js/mobiscroll.core-2.5.2-zh.js" type="text/javascript"></script>
 
 <link href="__PUBLIC__/css/mobiscroll.core-2.5.2.css" rel="stylesheet" type="text/css" />
 
 <script src="__PUBLIC__/js/mobiscroll.datetime-2.5.1.js" type="text/javascript"></script>
 
 <script src="__PUBLIC__/js/mobiscroll.datetime-2.5.1-zh.js" type="text/javascript"></script>
     <!-- S 可根据自己喜好引入样式风格文件 -->
 <script src="__PUBLIC__/js/mobiscroll.android-ics-2.5.2.js" type="text/javascript"></script>

<link href="__PUBLIC__/css/mobiscroll.android-ics-2.5.2.css" rel="stylesheet" type="text/css" />
<script src="__STATIC__/js/weui_zepto.min.js"></script>
<script src="__STATIC__/js/picker.js"></script>
<script src="__STATIC__/js/select.js"></script>
<script src="__STATIC__/js/iscroll.js"></script>
<script>

/*function tabindex(num){
  $('.tab_hd li a').css({'border-bottom':0,'color':'inherit'})
  $('.tab_head'+num).css({'border-bottom':'2px solid #ec3913','color':'#ec3913'})
  $(".ajax_return").width($(window).width());
  $.ajax({
      type : "GET",
      url:"/index.php?m=Mobile&c=User&a=shopactive&num="+num,//+tab,
      success: function(data)
      {
          $(".ajax_return").html(data);
      }
    }); 
}*/
$('#start_time,#end_time').val(getNowFormatDate());

 //datetime插件

       $(function () {
        

         var currYear = (new Date()).getFullYear();  

         var opt={};

         opt.date = {preset : 'date'};

         //opt.datetime = { preset : 'datetime', minDate: new Date(2012,3,10,9,22), maxDate: new Date(2014,7,30,15,44), stepMinute: 5  };

         opt.datetime = {preset : 'datetime'};

         opt.time = {preset : 'time'};

         opt.default = {

                 theme: 'android-ics light', //皮肤样式

                display: 'modal', //显示方式 

                mode: 'scroller', //日期选择模式

                lang:'zh',
                startYear:currYear - 10, //开始年份

                endYear:currYear + 10 //结束年份

         };

         $("#start_time").scroller('destroy').scroller($.extend(opt['date'], opt['default']));
         $("#end_time").scroller('destroy').scroller($.extend(opt['date'], opt['default']));

    });

$("#shop_list").select({
        title: "请选择店面",
        multi: true,
        split:',',
        closeText:'完成',
        items: JSON.parse('{$list}'),
       /* onChange: function(d) {
          $.alert("你选择了"+d.values+d.titles);
        }*/
      });
var myScroll;
function loaded () {
  myScroll = new IScroll('#wrapper', { eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false });
}
$('#search').click(function(){
    var start_time=$('#start_time').val();
    var end_time=$('#end_time').val();
    var shop_list=$('#shop_list').attr('data-values');
    if(shop_list==undefined){
      shop_list="";
    }
    var shops=shop_list.split(',');
    var shop_name=$('#shop_list').val();
    var shopstr="";

    for(var i=0;i<shops.length;i++){
      shopstr+="'"+shops[i]+"',";
    }
    shopstr=shopstr.substr(0,shopstr.length-1);
    $.showLoading();
    $.post('{:U("User/company_table")}',{start_time:start_time,end_time:end_time,shop_list:shopstr,shop_name:shop_name,shop_num:shop_list},function(res){
      $('.ajax_return').html(res);
      $.hideLoading();
      loaded();
    })
})

function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
  function TableToJson(tableid) {
    var txt = "[";
    var table = document.getElementById(tableid);
    var row = table.getElementsByTagName("tr");
    var col = row[0].getElementsByTagName("th");
    var title = "{";
    for(var i=0;i<col.length;i++){
         title += "\"" + i+ "\"\:\"" + col[i].innerHTML + "\",";
    }
    title = title.substring(0, title.length - 1);
    title+="}"

    for (var j = 1; j < row.length; j++) {
        var r = "{";
        for (var i = 0; i < col.length; i++) {
            var tds = row[j].getElementsByTagName("td");
            r += "\"" + col[i].innerHTML + "\"\:\"" + tds[i].innerHTML + "\",";
        }
        r = r.substring(0, r.length - 1)
        r += "},";
        txt += r;
    }
    txt = txt.substring(0, txt.length - 1);
    txt += "]";
    $('#jsondata').val(txt);
    $('#title').val(title);
    $('#export').submit();
    //alert($('#title').val())

   
}
</script>
</html>